package com.inspectortime.webapp;

import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.inspectortime.util.SpringValidatorUtils;
import com.mkode.util.java.lang.ClassUtils;

public class InspectionExtraInformationValidator implements Validator {
	
	public boolean supports(Class clazz) {
		return ClassUtils.isInstanceOf(clazz, InspectionCriteria.class);
	}

	public void validate(Object target, Errors errors) {
		InspectionCriteria inspectionCriteria = (InspectionCriteria) target;
		
		if (StringUtils.hasText(inspectionCriteria.getInspection().getComments())) {
			SpringValidatorUtils.rejectIfTooLong(errors, "inspection.comments", "tooLong", 4000);
		}
		
	}
		
}
